package com;

import org.junit.Test;

public class test123 {

    public String getString(String str){
        StringBuilder strb = new StringBuilder();
        char[] chars = str.toCharArray();
        int l = 0, r = chars.length - 1;
        while(l<=r){
            if(chars[l] < chars[r]){
                strb.append(chars[l++]);
            }else if(chars[l] > chars[l]){
                strb.append(chars[r--]);
            }else{
                int left = l ;
                int right = r;
                while(left < right &&chars[left] == chars[right]){
                    left++;
                    right--;
                }
                strb.append(chars[left] < chars[right] ? chars[l++] : chars[r--]);
            }

        }
        return strb.toString();
    }

    @Test
    public void test(){
        String str = "ACDBCB";
        System.out.println(getString(str));
    }
}
